package cz.data.common.base;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Optional;

@Getter
@Setter
public class TableDataResponse<T> extends BaseResponse {

    private List<T> data;
    private Integer total;

    public TableDataResponse() {
    }

    public TableDataResponse(List<T> data) {
        this(data, data.size());
    }

    public TableDataResponse(List<T> data, Long total) {
        this(data, Optional.ofNullable(total).map(Long::intValue).orElse(data.size()));
    }

    public TableDataResponse(List<T> data, int total) {
        this.data = data;
        this.total = total;
        success(this);
    }
}
